package com.sky.controller.user;


import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShopCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "C端-购物车接口")
@RestController
@RequestMapping("/user/shoppingCart")
public class ShopCartController {
    @Autowired
    private ShopCartService shopCartService;


    @ApiOperation("添加商品")
    @PostMapping("/add")
    public Result addCart(@RequestBody ShoppingCartDTO shoppingCartDTO)
    {
        shopCartService.addCart(shoppingCartDTO);
        return Result.success();
    }

    @ApiOperation("查看购物车")
    @GetMapping("/list")
    public Result<List<ShoppingCart>> list()
    {
        List<ShoppingCart> shoppingCart = shopCartService.list();
        return Result.success(shoppingCart);
    }

    @ApiOperation("清空购物车")
    @DeleteMapping("/clean")
    public Result clean()
    {
        shopCartService.clean();
        return Result.success();
    }

    @ApiOperation("删除购物车商品")
    @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO)
    {
        shopCartService.sub(shoppingCartDTO);
        return Result.success();
    }
}
